<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>粘性定位</title>
</head>
<style>
    body {
        height: 3000px;
    }
    .nav {
        /*粘性定位*/
        position: sticky;
        top: 0;
        width: 800px;
        height: 50px;
        background-color: gray;
        margin: 100px auto;
    }
</style>
<body>
    <div class="nav">导航栏</div>
</body>
</html>